#pragma once

#include <string>

std::string opers = "+-*/%";

enum
{
    DIVZERO = 1,
    MODZERO,
    Unkonw
};

class Task
{
public:
    Task()
    {}

    Task(int x, int y, char oper)
        : _data1(x)
        , _data2(y)
        , _oper(oper)
        , _result(0)
        , _exitcode(0)
    {}

    void run()
    {
        switch(_oper)
        {
            case '+':
                _result = _data1 + _data2;
                break;
            case '-':
                _result = _data1 - _data2;
                break;
            case '*':
                _result = _data1 * _data2;
                break;
            case '/':
                {
                    if(_data2 == 0)
                        _exitcode = DIVZERO;
                    else
                        _result = _data1 / _data2;
                }
                break;
            case '%':
                {
                    if(_data2 == 0)
                        _exitcode = MODZERO;
                    else
                        _result = _data1 % _data2;
                }
                break;
            default:
                _exitcode = Unkonw;
                break;
        }
    }

    void operator()()
    {
        run();
    }

    std::string GetResult()
    {
        std::string s = std::to_string(_data1);
        s += _oper;
        s += std::to_string(_data2);
        s += "=";
        s += std::to_string(_result);
        s += " [code: ";
        s += std::to_string(_exitcode);
        s += "]";

        return s;
    }

    std::string GetTask()
    {
        std::string s = std::to_string(_data1);
        s += _oper;
        s += std::to_string(_data2);
        s += "=?";

        return s;
    }

    ~Task()
    {}

private:
    int _data1;
    int _data2;
    char _oper;

    int _result;
    int _exitcode;
};